package bud.mobile.service;

import java.util.List;

import bud.mobile.dao.IMobileMemberDao;
import bud.vo.ChatDTO;
import bud.vo.CommentMemberDTO;
import bud.vo.CommentShopDTO;
import bud.vo.FriendDTO;
import bud.vo.MemberDTO;
import bud.vo.ShopDTO;

public class MobileMemberServiceImpl implements IMobileMemberService{

	private IMobileMemberDao dao;
	
	public IMobileMemberDao getDao() {
		return dao;
	}
	public void setDao(IMobileMemberDao dao) {
		this.dao = dao;
	}

	@Override
	public MemberResult insertMember(MemberDTO member) {
		if (member.getMem_email()==null || member.getMem_email()==""){
			return MemberResult.Failed;
		}
		String mem_email = member.getMem_email();
		MemberDTO tempMember = dao.getMemberByEmail(mem_email);
		if(tempMember == null){
			int result = dao.insertMember(member);
			if(result >= 1){
				return MemberResult.OK;
			} else {
				return MemberResult.Failed;
			}
		} else {
			return MemberResult.EmailDuplicated;
		}
	}

	@Override
	public MemberResult deleteMember(MemberDTO member) {
		int result = dao.deleteMember(member);
		return MemberResult.OK;
	}

	@Override
	public MemberResult updateMember(MemberDTO member) {
		int result = dao.updateMember(member);
		return MemberResult.OK;
	}

	@Override
	public MemberDTO getMember(Integer mem_no) {
		return dao.getMember(mem_no);
	}
	@Override
	public MemberDTO getMemberByEmail(String mem_email) {
		return dao.getMemberByEmail(mem_email);
	}
	@Override
	public ShopDTO getShop(Integer sh_no) {
		return dao.getShop(sh_no);
	}
	@Override
	public List<ShopDTO> getShopList() {
		return dao.getShopList();
	}
	
	
	
	@Override
	public List<CommentShopDTO> getCommentShop(int cs_ref_key) {
		return dao.getCommentShop(cs_ref_key);
	}
	@Override
	public int insertCommentShop(CommentShopDTO commentShop) {
		return dao.insertCommentShop(commentShop);
	}
	@Override
	public int deleteCommentShop(int cs_no) {
		return dao.deleteCommentShop(cs_no);
	}
	@Override
	public List<CommentMemberDTO> getCommentMember(int cm_ref_key) {
		return dao.getCommentMember(cm_ref_key);
	}
	@Override
	public int insertCommentMember(CommentMemberDTO memberShop) {
		return dao.insertCommentMember(memberShop);
	}
	@Override
	public int deleteCommentMember(int cs_no) {
		return dao.deleteCommentMember(cs_no);
	}
	@Override
	public MemberResult insertFriend(FriendDTO friend) {
		try {
			dao.insertFriend(friend);
		} catch (Exception e) {
			return MemberResult.Failed;
		}
		return MemberResult.OK;
	}
	@Override
	public List<FriendDTO> getRequestFriendList(Integer mem_no) {
		return dao.getRequestFriendList(mem_no);
	}
	@Override
	public MemberResult updateFriend(FriendDTO friend) {
		int result = dao.updateFriend(friend);
		return MemberResult.OK;
	}
	@Override
	public MemberResult deleteFriend(FriendDTO friend) {
		int result = dao.deleteFriend(friend);
		return MemberResult.OK;
	}
	@Override
	public List<ChatDTO> getChat(ChatDTO chat) {
		return dao.getChat(chat);
	}
	@Override
	public MemberResult insertChat(ChatDTO chat) {
		int result = dao.insertChat(chat);
		return MemberResult.OK;
	}
	@Override
	public ChatDTO getRecentChat(ChatDTO chat) {
		return dao.getRecentChat(chat);
	}
	@Override
	public boolean getIsRequestFriend(FriendDTO friend) {
		FriendDTO temp = dao.getIsRequestFriend(friend);
		if (temp == null){
			return false;
		}
		return true;
	}
	
}
